﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nancy;
using Nancy.TinyIoc;
using Nancy.Session;

namespace YAPSAR.Web
{
    public class CustomNancyBootstrapper : DefaultNancyBootstrapper
    {
        protected override void ApplicationStartup(TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines)
        {
            base.ApplicationStartup(container, pipelines);

            CookieBasedSessions.Enable(pipelines);

            this.Conventions.ViewLocationConventions.Add((viewName, model, context) =>
            {
                if (String.IsNullOrWhiteSpace(context.ModulePath) == false)
                {
                    // We have a module/request path, so we will use that to try and find the view
                    return String.Concat("Web/", viewName, "/", context.ModulePath);
                }

                // We do not have a module path, so we will look for view in "Web/{Name}/"
                return String.Concat("Web/", viewName, "/", viewName);
            });
        }
    }
}
